<?php
class TopHeaderStylesWidget  extends CWidget{
    
	//输出字符串
	private $out = '';
    
    private $controller= '';
    
    private $action= '';
	
	private $modules = '';

	public function init(){
        $this->controller = Yii::app()->controller->id;  
        $this->action = Yii::app()->controller->action->id;
		$this->modules = isset(Yii::app()->controller->module->id) ? Yii::app()->controller->module->id : '';
	}

	public function run(){
        $this->generateTopHeaderStyles();
		echo $this->out;
	}
    
    public function generateTopHeaderStyles(){
        $baseUrl = Yii::app()->request->baseUrl;

        
        $this->out .= <<<OUT
<!-- CSS 样式 -->
        <link href="{$baseUrl}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <link href="{$baseUrl}/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">\n
OUT;

        //前台和后台的css变换
        if($this->modules == 'admin'){
            $this->out .= <<<OUT
        <link href='{$baseUrl}/css/flat-ui-admin.css' rel='stylesheet'>
        <link href='{$baseUrl}/css/flatui-docs.css' rel='stylesheet'>\n
OUT;
        }else{
            $this->out .= <<<OUT
        <link href='{$baseUrl}/css/flat-ui.css' rel='stylesheet'/>
        <link href='{$baseUrl}/css/docs.css' rel='stylesheet'>\n
OUT;
        }

        //fancybox toptab
        $this->out .= <<<OUT
        <link href="{$baseUrl}/fancyBox/source/jquery.fancybox.css" rel="stylesheet">
        <link href="{$baseUrl}/css/themes/tab.css" rel="stylesheet">\n
OUT;
        //搜索框的样式
        if($this->action == 'search' && $this->controller == 'site'){
            $this->out .= <<<OUT
        <link href="{$baseUrl}/css/flatui-docs-search.css" rel="stylesheet">
OUT;
        }

        //代码高亮css引入
        if($this->action == 'view' && $this->controller == 'site'){
            $this->out .= <<<OUT
        <link href="{$baseUrl}/syntaxhighlighter/styles/shCore.css" rel="stylesheet">
        <link href="{$baseUrl}/syntaxhighlighter/styles/shThemeFlatUI.css" rel="stylesheet">
OUT;
        }

        $this->out .= "\n";


    }
}


